package com.zwj.vo;

import com.zwj.common.enums.EnumErrorCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "返回结果")
@SuppressWarnings("all")
public class BaseResp<T> {
    @ApiModelProperty(value = "请求状态码 200：成功 10001：用户未登录 10002：用户未授权", example = "200")
    private String code;
    @ApiModelProperty(value = "信息", example = "请求成功")
    private String msg;
    @ApiModelProperty(value = "数据", example = "true")
    private T data;

    public static <T> BaseResp<T> ok(T data) {
        return new BaseResp<T>("200", "请求成功", data);
    }

    public static BaseResp<String> ok() {
        return ok(null);
    }

    public static BaseResp fail() {
        return new BaseResp(EnumErrorCode.REQUEST_FAIL.getCode(), EnumErrorCode.REQUEST_FAIL.getMsg(), null);
    }

    public static BaseResp fail(EnumErrorCode errorCode) {
        return new BaseResp(errorCode.getCode(), errorCode.getMsg(), null);
    }
}
